package com.huashi.dealer.modular.business.writeoff.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huashi.dealer.commonEntity.UserWriteoffLog;
import com.huashi.dealer.core.exception.CommonException;
import com.huashi.dealer.core.util.SaTokenUtil;
import com.huashi.dealer.modular.business.writeoff.mapper.WriteoffMapper;
import com.huashi.dealer.modular.business.writeoff.service.WriteoffService;
import com.huashi.dealer.modular.business.writeoff.param.WriteoffResponseParam;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * API核销服务实现类
 *
 * @author 谭陈强
 * @since 2025-07-30
 */
@Service("apiWriteoffServiceImpl")
public class WriteoffServiceImpl extends ServiceImpl<WriteoffMapper, UserWriteoffLog> implements WriteoffService {

    @Resource
    private WriteoffMapper writeoffMapper;

    @Override
    public WriteoffResponseParam getWriteoffLogList(String token, Integer page, Integer listRows) {
        // TODO: 实现获取核销日志列表逻辑
        WriteoffResponseParam responseParam = new WriteoffResponseParam();
        // 这里需要实现具体的业务逻辑
        return responseParam;
    }

    @Override
    public Page<UserWriteoffLog> getWriteoffLogList(Page<UserWriteoffLog> page,Integer type) {
        try {
            // 获取当前登录用户ID
            Long userId = SaTokenUtil.getLoginId();

            // 调用mapper获取核销日志列表
            Page<UserWriteoffLog> writeoffLogPage = writeoffMapper.getWriteoffLogList(userId, page, type);
            return writeoffLogPage;
        } catch (Exception e) {
            throw new CommonException("获取核销日志列表失败：" + e.getMessage());
        }
    }
} 